package xp.ass.imitate.infra.express;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.Test;


/**
 * @author chent3
 * @date 2024/9/5
 */
@Slf4j
public class CompressTwoIntegers {


    @Test
    public void highPerformanceCompress() {
        int big = 16;
        int small = 5;
        int compressVal = compressInteger(16, 5);

        log.info("compress value : ( {}, {} ) => {}", big, small, compressVal);
        log.info("decompress value : （{}）=> {}", compressVal, decompressInteger(compressVal));
    }


    public Integer compressInteger(Integer big, Integer small) {
        return (big << 16) + small;
    }

    public Pair<Integer, Integer> decompressInteger(Integer compressVal) {
        return Pair.of(
                compressVal >> 16,
                compressVal & 0xFFFF
        );
    }
}
